<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use app\models\message;

class MessageController extends Controller{
     public $enableCsrfValidation = false;
     //获取消息
     public function actionGet(){
           $model = new message();
           if(Yii::$app->request->isPost){
              $postData = Yii::$app->request->post();
              $openid = $postData['openid'];
              
              $sql = "select messageId,content,createTime,openid,senderId from freshmanHelper_message where openid = '$openid' and state = 0 or state = 1";
              $data = message::findBysql($sql)->asArray()->all();
              echo json_encode(array('error' => 0,'message' => 'success','data' => $data,));
            }
       }     

     public function actionReaded(){
           $model = new message();
           if(Yii::$app->request->isPost){
               $postData = Yii::$app->request->post();
               $messageId = $postData['id'];
               $data = $model->updateAll(['state' => 1 ],['messageId' => $messageId]);
               echo json_encode(array('error' => 0,'message' => 'success','data' => $data,));
             }
         }

     public function actionDeleted(){
         $model = new message();
         if(Yii::$app->request->isPost){
             $postData = Yii::$app->request->post();
             $messageId = $postData['id'];
             $data = $model->updateAll(['state' => 2 ],['messageId' => $messageId]);
             echo json_encode(array('error' => 0,'message' => 'success','data' => $data,));
             }
         }
 }



